package com.jingdianjichi.wx.service.impl;

import com.jingdianjichi.wx.ai.SiliconFlowClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class ChatService {
    private final SiliconFlowClient ai;

    public String reply(String userText) {
        try {
            String ans = ai.chatOnce(userText == null ? "" : userText.trim());
            return (ans == null || ans.isEmpty()) ? "我这边暂时没有合适的回答哦~" : ans;
        } catch (Exception e) {
            log.warn("AI调用失败: {}", e.toString());
            return "服务繁忙，请稍后再试~";
        }
    }
}
